/**
 * Created by alan on 2017/4/27.
 * 水质信息
 */
Ext.define('Admin.view.waterDispath.DdsDrWqController', {
	extend: 'Ext.app.ViewController',
	alias: 'controller.ddsDrWqController',

	init: function() {

	},

	//steps下一步
	check: function() {
		var ddsDrWqGrid = this.lookupReference('ddsDrWqGrid');
		var store = ddsDrWqGrid.getStore();
		 var stcd = this.lookupReference('stcd').getValue();
		var startTm = this.lookupReference('startTm').getValue();
		var endTm = this.lookupReference('endTm').getValue();
		if(startTm > endTm) {
			Ext.Msg.alert('提示', '起始时间需要小于结束时间'); //这种方式非常常见的
			return;
		}
		var norm = this.lookupReference('norm').getValue();
		switch (norm) {
			case "1":
			ddsDrWqGrid.setColumns([
				{
					header: '采样时间',
					dataIndex: 'spt',
					align: 'center',
					flex: 1,
					renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s')
				},
				{
					header: '水温(&#8451;)',
					dataIndex: 'wt',
					align: 'center',
					flex: 1
				}]);
			break;
			case "2":
			ddsDrWqGrid.setColumns([
				{
					header: '采样时间',
					dataIndex: 'spt',
					align: 'center',
					flex: 1,
					renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s')
				},
				{
					header: 'PH(无量纲)',
					dataIndex: 'ph',
					align: 'center',
					flex: 1
				}]);
			break;
			case "3":
			ddsDrWqGrid.setColumns([
				{
					header: '采样时间',
					dataIndex: 'spt',
					align: 'center',
					flex: 1,
					renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s')
				},
				{
					header: '化学需氧量(mg/L)',
					dataIndex: 'codcr',
					align: 'center',
					flex: 1
				}]);
			break;
			case "4":
			ddsDrWqGrid.setColumns([
				{
					header: '采样时间',
					dataIndex: 'spt',
					align: 'center',
					flex: 1,
					renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s')
				},
				{
					header: '高锰酸盐(mg/L)',
					dataIndex: 'codmn',
					align: 'center',
					flex: 1
				}]);
			break;
			case "5":
			ddsDrWqGrid.setColumns([
				{
					header: '采样时间',
					dataIndex: 'spt',
					align: 'center',
					flex: 1,
					renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s')
				},{
					header: '氨氮(mg/L)',
					dataIndex: 'nh3n',
					align: 'center',
					flex: 1
				}]);
			break;
			case "6":
			ddsDrWqGrid.setColumns([
				{
					header: '采样时间',
					dataIndex: 'spt',
					align: 'center',
					flex: 1,
					renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s')
				},{
					header: '总磷(mg/L)',
					dataIndex: 'tp',
					align: 'center',
					flex: 1
				}]);
			break;
		}



		store.getProxy().extraParams = {
			river: config.RIVER,
			stcd: stcd,
			startTm: (startTm == null ? startTm : Ext.Date.format(startTm, 'Y-m-d H:i:s')),
			endTm: (endTm == null ? endTm : Ext.Date.format(endTm, 'Y-m-d H:i:s'))
		};
		store.reload();
	},

	changeDate: function(tm) {
		var tmDate = new Date(tm);
		var y = tmDate.getFullYear();
		var m = tmDate.getMonth() + 1;
		m = m < 10 ? ('0' + m) : m;
		var d = tmDate.getDate();
		d = d < 10 ? ('0' + d) : d;
		var h = tmDate.getHours();
		h = h < 10 ? ('0' + h) : h;
		var minute = tmDate.getMinutes();
		minute = minute < 10 ? ('0' + minute) : minute;
		var second = tmDate.getSeconds();
		second = second < 10 ? ('0' + second) : second;
		return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
	}
})
